import React, { Component, forwardRef } from 'react'
import { findDOMNode } from 'react-dom'

// for(){const let  = 1;}

const ChildInput = forwardRef((props, ref) => {
  return (
    <div>
      <input ref={ref} />
    </div>
  )
})

class ClassInput extends React.Component {
  constructor(props) {
    super(props)

    // this.myChildRef = React.createRef()
  }

  // handleFocus = () => {
  //   console.log(this.myChildRef.current)
  //   this.myChildRef.current.focus()
  // }

  render() {
    return <input />
  }
}

export default class Ref extends Component {
  constructor(props) {
    super(props)

    this.myRef = React.createRef() // 创建ref引用
  }
  componentDidMount() {
    // console.log(this.myRef.current.focus())
    // this.myRef.current.focus()

    // console.log(this.myRef.current.handleFocus())

    const node = findDOMNode(this.myRef.current)
    console.log(node.focus(), 'node')
  }
  render() {
    return (
      <div>
        {/* <input ref={this.myRef} /> */}
        {/* <ChildInput ref={this.myRef} /> */}

        <ClassInput ref={this.myRef} />
      </div>
    )
  }
}
